package com.sgb.kjwl.view.ui.adapter.self.carMasters;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.CarriageInfoPublishEntity;
import com.sgb.kjwl.utils.NumberUtil;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class CarriageManageAdapter extends BaseRecycleAdapter<CarriageInfoPublishEntity> {

    private TextView tv_car_type;
    String areaCode;
    boolean isSelectHistory;//是否是历史承运

    public CarriageManageAdapter(Context context, List<CarriageInfoPublishEntity> datas) {
        super(context, R.layout.item_carriage_manage, datas);
        this.areaCode=areaCode;
    }

    public void setSelectHistory(boolean selectHistory) {
        isSelectHistory = selectHistory;
    }

    @Override
    public void convert(ItemViewHolder holder, final CarriageInfoPublishEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        tv_car_type = holder.itemView.findViewById(R.id.tv_car_type);
        if(!TextUtils.isEmpty(entity.getCarTypeName())) {
            tv_car_type.setText(entity.getCarTypeName() + "/" + entity.getCarLenName());
        }
        if(entity.getDiscuss()==1){
            holder.setText(R.id.tv_freight, "商议");
        }else {
            StringBuilder builder = new StringBuilder();
            if (entity.getKilometre() != 0) {
                builder.append(NumberUtil.trim0(entity.getKilometre())).append("公里内");
            }
            builder.append(NumberUtil.trim0(entity.getFreight())).append("元").append(entity.getFreightUnitWords());
            holder.setText(R.id.tv_freight, builder.toString());
        }
        if(isSelectHistory) {
          LinearLayout llTop=  holder.itemView.findViewById(R.id.ll_top);
          LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)llTop.getLayoutParams();
            params.setMargins(0,0,0,0);
            llTop.setLayoutParams(params);
            llTop.setPadding(40,0,0,0);
            TextView tvState =holder.getItem().findViewById(R.id.goods_sources_state);
            switch (entity.getCarrierType()){
                case 1:
                    tvState.setBackgroundResource(R.drawable.carrier_ordinary);
                    break;
                case 2:
                    tvState.setBackgroundResource(R.drawable.carrier_bidding);
                    break;
                case 3:
                    tvState.setBackgroundResource(R.drawable.carrier_special_offer);
                    break;
            }
        }else {
          //  holder.itemView.findViewById(R.id.showView).setVisibility(View.VISIBLE);
        }
        ImageView ivTag=holder.itemView.findViewById(R.id.iv_tag);
        TextView tvTime=holder.getItem().findViewById(R.id.tv_time);
        if(DateUtils.stampToDay5(entity.getInTime()).equals(DateUtils.stampToDay5(entity.getShipmentEndTime()))){
            tvTime.setText(DateUtils.stampToDay5(entity.getInTime()));
        }else {
            tvTime.setText(DateUtils.stampToDay5(entity.getInTime()) + "-" + DateUtils.stampToDay5(entity.getShipmentEndTime()));
        }
        int status;
        //消息状态 1:生效/2:失效
        if ("1".equals(entity.getMessageStatus())) {
            status = R.drawable.ic_take_effect;
        } else if ("2".equals(entity.getMessageStatus())) {
            status = R.drawable.ic_take_effect_un;
        } else {
            status = R.color.transparent;
        }
        ivTag.setImageResource(status);

        if (entity.getUpdateTime() != 0) {
            holder.setText(R.id.tv_update_time, "更新时间：" + DateUtils.timestampTo13DateNos(entity.getUpdateTime()));
        }
    }



}
